package vistas;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.JLabel;
import java.awt.Font;
import java.sql.ResultSet;

import javax.swing.JTextField;
import javax.swing.JTable;

import clases.cargos_class;
import javax.swing.JPopupMenu;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import java.awt.Cursor;

public class Buscarcargosform extends JInternalFrame {

	private final JPanel contentPanel = new JPanel();
	private JTextField tcargos;
	private JTable tabla_cargos;
	private ResultSet resultado;
	private int filas;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			Buscarcargosform dialog = new Buscarcargosform(0);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public Buscarcargosform(int tipo) {
		setFrameIcon(new ImageIcon(Asignarhorarios_buscarform.class.getResource("/icons/extra.png")));
		setClosable(true);
		setIconifiable(true);
		setTitle("Buscar Cargo");
		setBounds(100, 100, 535, 387);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		JLabel label = new JLabel("Nombres");
		label.setFont(new Font("Tahoma", Font.PLAIN, 13));
		label.setBounds(10, 13, 59, 16);
		contentPanel.add(label);
		
		tcargos = new JTextField();
		tcargos.setFont(new Font("Tahoma", Font.PLAIN, 13));
		tcargos.setColumns(10);
		tcargos.setBounds(79, 11, 308, 20);
		contentPanel.add(tcargos);
		
		JButton button = new JButton("Buscar");
		button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		button.setContentAreaFilled(false);
		button.setIcon(new ImageIcon(Buscarcargosform.class.getResource("/icons/buscar.png")));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		button.setBounds(397, 11, 108, 23);
		contentPanel.add(button);
		
		tabla_cargos = new JTable();
		tabla_cargos.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"Codigo", "Cargo"
			}
		) {	
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			boolean[] columnEditables = new boolean[] {
				true, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		tabla_cargos.getColumnModel().getColumn(0).setPreferredWidth(0);
		tabla_cargos.getColumnModel().getColumn(0).setMinWidth(0);
		tabla_cargos.getColumnModel().getColumn(0).setMaxWidth(0);
		tabla_cargos.setBounds(10, 40, 495, 297);
		contentPanel.add(tabla_cargos);
		
		JPopupMenu popupMenu = new JPopupMenu();
		addPopup(tabla_cargos, popupMenu);
		
		JMenuItem mntmModificar = new JMenuItem("Modificar");
		mntmModificar.setIcon(new ImageIcon(Buscarcargosform.class.getResource("/icons/modificar_pq.png")));
		mntmModificar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(tabla_cargos.getSelectedRow()>-1)
				{
					Ingresarcargosform cargos = new Ingresarcargosform(tabla_cargos.getValueAt(tabla_cargos.getSelectedRow(), 0).toString());
					cargos.setVisible(true);
				}
			}
		});
		popupMenu.add(mntmModificar);
		
		
		
	
	}
	private static void addPopup(Component component, final JPopupMenu popup) {
		component.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			public void mouseReleased(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			private void showMenu(MouseEvent e) {
				popup.show(e.getComponent(), e.getX(), e.getY());
			}
		});
	}
}
